<?php

namespace addons\shopro\model;

use addons\shopro\exception\Exception;
use think\Model;
use app\common\library\Auth;
use think\Db;
use think\Log;
use traits\model\SoftDelete;

/**
 *
 */
class Cats extends Model
{

    protected $name = 'shopro_cats';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = false;


    public function catBreed()
    {
        return $this->hasOne(Breed::class, 'id', 'pid')->field('id,name');
    }

    /**
     * 猫咪性别
     * @param $value
     * @return string
     * @Author ycr <E-mail:yuncran@126.com>
     */
    public function getGenderAttr($value)
    {
        return $value == 1 ? '公' : '母';
    }

    /**
     * 图片地址处理
     * @param $value
     * @return string
     * @Author ycr <E-mail:yuncran@126.com>
     */
    public function getImageAttr($value)
    {
        return cdnurl($value, true);
    }

    public function getImagesAttr($value)
    {
        $arr = explode(',', $value);
        foreach ($arr as &$val) {
            $val = cdnurl($val, true);
        }
        unset($val);
        return $arr;
    }


}
